from services import user_service
from utils.password_util import verify_or_compare_password as verify_password
from utils.jwt_util import create_access_token

def login(username, password):
    user = user_service.getUserByUsername(username)
    if not user or not verify_password(password, user['hashed_password']):
        return None
    access_token = create_access_token(data={"sub": user['username'], "user_id": user['id']})
    return {"access_token": access_token, "token_type": "bearer"}
